<?php 
$this->lang->load('admin_link', $this->session->admin_language);
$this->load->view('admin/layout/head', array('title'=>$this->lang->line('link')), FALSE);
?>

<div id="container">
<ul class="nav nav-tabs" id="subject-tab">
	<li class="active"><a href="javascript:;"><?php echo isset($link)?$this->lang->line('edit'):$this->lang->line('add') ?></a></li>
</ul>
<form class="form-inline deal-from container-fluid no-padding" id="link-form">
	<input type="hidden" name="id" value="<?php echo isset($link['id'])?$link['id']:0 ?>">
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('title') ?></label>
		<div class="form-group">
			<input type="text" name="title" class="form-control" value="<?php echo isset($link['title'])?$link['title']:''?>" style="width: 600px">
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('url') ?></label>
		<div class="form-group">
			<input type="text" name="url" class="form-control" value="<?php echo isset($link['url'])?$link['url']:''?>" style="width: 600px">
		</div>
	</div>
	
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('sort') ?></label>
		<div class="form-group" >
			<input type="text" name="sort" class="form-control" value="<?php echo isset($link['sort'])?$link['sort']:'0'?>" style="width: 100px">
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('remark') ?></label>
		<div class="form-group">
			<input type="text" name="remark" class="form-control" value="<?php echo isset($link['remark'])?$link['remark']:''?>" style="width: 600px">
		</div>
	</div>

	<div style="padding-left:110px" class="mt-20">
      <a href="javascript:;" class="btn btn-primary save"><?php echo $this->lang->line('save') ?></a>
      <a href="<?php echo $back_url ?>" class="btn btn-default cancel"><?php echo $this->lang->line('cancel') ?></a>
    </div>

	
</form>
</div>


<?php 

$this->load->view('admin/layout/footer');
?>
<script type="text/javascript">

	
	$('.save').click(function(event) {
		
		if(!$('input[name=title]').val()){
			alert('<?php echo $this->lang->line('submit_error_title') ?>');
			return;
		}

		if(!$('input[name=url]').val()){
			alert('<?php echo $this->lang->line('submit_error_url') ?>');
			return;
		}

		Toast.loading();
		$.post('/admin/link/save', $('#link-form').serialize(), function(data, textStatus, xhr) {
			Toast.destory();
			var json = $.parseJSON(data);
			if(json.code == 1){
				alert('<?php echo $this->lang->line('submit_error') ?>');
				return;
			}
			if(json.code == 2){
				alert('<?php echo $this->lang->line('submit_error_input') ?>');
				return;
			}
			Toast.success('<?php echo $this->lang->line('submit_success') ?>',function(){
				window.location = '<?php echo $back_url ?>';
			})

		});
	});
</script>